using System;
using System.Collections.Generic;
using System.Collections;
using System.Text;
using System.Web;

using Common;

namespace data
{
    public class newsLibs
    {
        public static string lastErrorMessage = "";

        public static newsDataSetTableAdapters.tm_newsTableAdapter newsTA = new data.newsDataSetTableAdapters.tm_newsTableAdapter();
        public static newsDataSetTableAdapters.tm_newsStatTableAdapter newsStatTA = new data.newsDataSetTableAdapters.tm_newsStatTableAdapter();
        public static newsDataSetTableAdapters.tm_newsStatTableAdapter newsTypeTA = new data.newsDataSetTableAdapters.tm_newsStatTableAdapter();
        
        
        public static newsDataSet.tm_newsRow GetData(int newId)
        {
            newsDataSet.tm_newsDataTable newsTbl = new newsDataSet.tm_newsDataTable();
            try
            {
                newsTA.FillByNewId(newsTbl, newId);
                if (newsTbl.Count < 0) return null;
                return newsTbl[0];
            }
            catch (Exception ex)
            {
                lastErrorMessage = ex.Message.ToString();
            }
            return null;
        }
        public static newsDataSet.tm_newsDataTable GetDataByUser(int userId)
        {
            newsDataSet.tm_newsDataTable newsTbl = new newsDataSet.tm_newsDataTable();
            try
            {
                lastErrorMessage = "";
                newsTA.FillByUser(newsTbl, userId);
                return newsTbl;
            }
            catch (Exception ex)
            {
                lastErrorMessage = ex.Message.ToString();
            }
            return null;
        }

        public static int TotalNews(int userId)
        {
            try
            {
                lastErrorMessage = "";
                return (int)newsTA.TotalNews(userId);
            }
            catch (Exception ex)
            {
                lastErrorMessage = ex.ToString();
            }
            return -1;
        }
      }
}
